package com.example.myapplication.apter;

import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.fragment.app.FragmentManager;
import androidx.recyclerview.widget.RecyclerView;


import com.bumptech.glide.Glide;
import com.example.myapplication.New.HotdetailsActivity;
import com.example.myapplication.R;
import com.example.myapplication.ShuJu.MyappealBean;
import com.example.myapplication.ShuJu.Re_Servlet;
import com.example.myapplication.government.ClaimDdetailsActivity;


import java.util.List;

public class MyappealApter extends  RecyclerView.Adapter<MyappealApter.MyHolder>{
    private Context context ;
    private List<MyappealBean.RowsBean> list;
    private View view;


    public MyappealApter(Context context, List<MyappealBean.RowsBean> list) {
        this.context = context;
        this.list = list;

    }

    @NonNull
    @Override
    public MyappealApter.MyHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        //填充试图
        view = LayoutInflater.from(context).inflate(R.layout.item_news,null);
        return new MyappealApter.MyHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull MyappealApter.MyHolder holder, int position) {
        Glide.with(context).load("http://124.93.196.45:10001/"+list.get(position).getImgUrl()).into(holder.cover);
        holder.title.setText(list.get(position).getTitle());
        holder.content.setText(String.valueOf(list.get(position).getUndertaker()));
        holder.pubDate.setText(list.get(position).getCreateTime());
       if(list.get(position).getState().equals("0")){
           holder.contentNum.setText("未处理");
        }else {
           holder.contentNum.setText("已处理");
       }
       //点击标签进入详情
        holder.rootView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, ClaimDdetailsActivity.class);
                intent.putExtra("DemandApterID",String.valueOf(list.get(position).getId()));
                context.startActivity(intent);
            }
        });

    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class MyHolder extends RecyclerView.ViewHolder {
        ImageView cover;
        TextView title;
        TextView contentNum;
        TextView content;
        TextView pubDate;
        RelativeLayout rootView;
        public MyHolder(@NonNull View itemView) {
            super(itemView);
            cover = itemView.findViewById(R.id.cover);
            content = itemView.findViewById(R.id.content);
            title = itemView.findViewById(R.id.title);
            contentNum = itemView.findViewById(R.id.contentNum);
            pubDate = itemView.findViewById(R.id.pubDate);
            rootView = itemView.findViewById(R.id.rootView);
        }
    }
}

